﻿package plugin.bagN
{
    import com.sh.game.consts.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.display.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.component.*;
    import view.tips.*;

    public class BagFlashItem extends Box implements IComponent
    {
        private var _oldData:Object = null;
        private var _radio:Number = 0.6;
        public var _iconBm:Bitmap;
        public var _bgBm:Bitmap;
        private var _effect:TipsEffect;
        private var _light:XMLMovieClip;
        private var _curBmdUrl:String;
        private var _urlimg:String = "";

        public function BagFlashItem()
        {
            this.initView();
            return;
        }// end function

        protected function initView() : void
        {
            this._bgBm = new Bitmap(App.asset.getBitmapData("jpg.common.cs2_bagcell"));
            this.addChild(this._bgBm);
            var _loc_1:* = App.asset.getBitmapData("png.common.noramlicon");
            this._iconBm = new Bitmap(_loc_1);
            this._iconBm.scaleX = 0.65;
            this._iconBm.scaleY = 0.65;
            this._iconBm.x = 5;
            this._iconBm.y = 5;
            this.addChild(this._iconBm);
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            var _loc_5:Array = null;
            var _loc_6:int = 0;
            if (param1 == null || !param1.hasOwnProperty("icon"))
            {
                this._oldData = null;
                if (this._iconBm.parent)
                {
                    this._iconBm.parent.removeChild(this._iconBm);
                }
                this.disposeEffect();
                if (this._effect)
                {
                    this._effect.visible = false;
                }
                return;
            }
            else
            {
                if (this._iconBm.parent == null)
                {
                    this.addChildAt(this._iconBm, 1);
                }
                if (this._effect)
                {
                    this._effect.visible = true;
                }
            }
            if (param1.icon == "lock")
            {
                this._iconBm.x = 10;
                this._iconBm.y = 10;
                this._iconBm.scaleX = 1;
                this._iconBm.scaleY = 1;
            }
            else
            {
                this._iconBm.x = 5;
                this._iconBm.y = 5;
                this._iconBm.scaleX = 0.65;
                this._iconBm.scaleY = 0.65;
            }
            if (this._light && this._light.parent)
            {
                this.removeChild(this._light);
                this._light.dispose();
                this._light = null;
            }
            this._urlimg = "";
            this._oldData = param1;
            var _loc_2:* = this._oldData.light;
            if (_loc_2)
            {
                _loc_5 = _loc_2.split("#");
                _loc_6 = UserData.getUserData("career");
                if (_loc_5.length == 1)
                {
                    this.initEff2(_loc_5[0]);
                }
                else if (_loc_5.length == 3)
                {
                    this.initEff2(_loc_5[(_loc_6 - 1)]);
                }
                else
                {
                    this.initEff2(0);
                }
            }
            else
            {
                this.initEff2(0);
            }
            var _loc_3:* = UIGlobel.getItemd(1);
            var _loc_4:* = _loc_3 + this._oldData.icon + Config.IconExtension;
            App.mloader3.loadBMD(Config.getUrl(_loc_4, ResourceType.NORMAL), 1, new Handler(this.onComp));
            return;
        }// end function

        public function get data() : Object
        {
            return this._oldData;
        }// end function

        private function onComp(param1:BitmapData) : void
        {
            if (this._iconBm)
            {
                if (param1)
                {
                    this._iconBm.bitmapData = param1;
                }
                else
                {
                    this._iconBm.bitmapData = App.asset.getBitmapData("png.common.noramlicon");
                }
                this._iconBm.smoothing = true;
            }
            return;
        }// end function

        private function initEff2(param1:int) : void
        {
            if (param1 > 0)
            {
                this._urlimg = "assets/images/iconeffect/light" + param1 + ".swf";
                App.mloader3.loadSWF(Config.getUrl(this._urlimg), 1, new Handler(this.onComplight, [param1]));
            }
            return;
        }// end function

        private function onComplight(param1:int, param2:Object) : void
        {
            if (this._urlimg == "")
            {
                return;
            }
            var _loc_3:* = new XML(new EffItem.lightXmlDic[param1]);
            this._curBmdUrl = "light" + param1;
            this._light = new XMLMovieClip(this._curBmdUrl, _loc_3);
            if (param1 == 10)
            {
                this._light.scale = 0.6;
                this._light.interval = 1000 / 8;
                this._light.x = 0;
                this._light.y = 0;
            }
            else
            {
                this._light.scale = 0.6;
                this._light.interval = 1000 / 5;
                this._light.x = -1;
                this._light.y = -1;
            }
            this._light.play();
            this._light.blendMode = BlendMode.ADD;
            this._light.mouseChildren = false;
            this._light.mouseEnabled = false;
            this.addChild(this._light);
            return;
        }// end function

        public function disposeEffect() : void
        {
            if (this._effect)
            {
                if (this._effect.parent)
                {
                    this._effect.parent.removeChild(this._effect);
                }
                this._effect.dispose();
                this._effect = null;
            }
            if (this._light && this._light.parent)
            {
                this.removeChild(this._light);
                this._light.dispose();
                this._light = null;
            }
            this._urlimg = "";
            return;
        }// end function

        public function dispose() : void
        {
            if (this._effect)
            {
                if (this._effect.parent)
                {
                    this._effect.parent.removeChild(this._effect);
                }
                this._effect.dispose();
                this._effect = null;
            }
            if (this._bgBm)
            {
                if (this._bgBm.parent)
                {
                    this._bgBm.parent.removeChild(this._bgBm);
                }
                this._bgBm = null;
            }
            if (this._iconBm)
            {
                if (this._iconBm.parent)
                {
                    this._iconBm.parent.removeChild(this._iconBm);
                }
                this._iconBm = null;
            }
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            return;
        }// end function

        override public function get comXml() : Object
        {
            return null;
        }// end function

        override public function set comXml(param1:Object) : void
        {
            return;
        }// end function

    }
}
